//Component Object
import moment from "../../public/utils/moment"
Component({
    properties: {
        timeTab:{
          type:Boolean,
          value:true,
          observer: function(){}
        },
        signTab:{
          type:Boolean,
          value:true,
          observer: function(){}
        },
        achievementTab:{
          type:Boolean,
          value:true,
          observer: function(e){
          }
        },
    },
    data: {
        showTime: false,
        timeName:"一周内",
        showAchievement:false,
        achievementType:2,
        achievementName:"全部",

        showSign:false,
        signType:2,
        signName:"全部",

        currentTime: [`${moment().subtract(7, 'days').format("yyyy-MM-DD")} 00:00:00`, `${moment().format("yyyy-MM-DD")} 23:59:59`]

    },
    methods: {
        timeSearch() {
            this.setData({
              showTime: !this.data.showTime
            });
          },
        
          signSearch(){
            this.setData({
              showSign: !this.data.showSign
            });

          },
        
          achievemenSearch(){
            this.setData({
              showAchievement: !this.data.showAchievement
            });
          },
        
          closeSearch(){
            this.setData({
              showAchievement: false,
              showTime: false,
              showSign:false
            });
          },

          bindDateChange: function (e) {
            this.setData({
              currentTime: [`${moment(e.detail.value).format("yyyy-MM-DD")} 00:00:00`, `${moment(e.detail.value).format("yyyy-MM-DD")} 23:59:59`],
              timeName:e.detail.value
            });
            this.emitEvent();
          },

          emitEvent(){
            let formData = {
              currentTime:this.data.currentTime,
              achievementType:this.data.achievementType,
              signStatus:this.data.signType
            }

            this.triggerEvent("doSearch", formData)
          },
        
          doSearchTime(e) {
            const typeMethod= {
             

              '一周内': () => {
                this.setData({
                  currentTime: [`${moment().subtract(7, 'days').format("yyyy-MM-DD")} 00:00:00`, `${moment().add(7, 'days').format("yyyy-MM-DD")} 23:59:59`]
                })
              },
             
              //一个月内
              '一个月内': () => {
                this.setData({
                  currentTime: [`${moment().subtract(1, 'months').format("yyyy-MM-DD")} 00:00:00`, `${moment().add(1, 'months').format("yyyy-MM-DD")} 23:59:59`]
                })
              },
              //三个月内
              '三个月内': () => {
                this.setData({
                  currentTime: [`${moment().subtract(3, 'months').format("yyyy-MM-DD")} 00:00:00`, `${moment().add(3, 'months').format("yyyy-MM-DD")} 23:59:59`]
                })
              },
            }
        
            this.setData({timeName:e.target.dataset.type})
            typeMethod[e.target.dataset.type]();
            this.emitEvent();
          },


          doSearchSign(e) {
            const typeMethod= {
              //全部
              '2': () => {
                this.setData({
                  signName: '全部'
                })
              },
              //合格
              '1': () => {
                this.setData({
                  signName: '已签到'
                })
              },
              //未合格
              '0': () => {
                this.setData({
                  signName: '未签到'
                })
              }
             
            }
        
            this.setData({signType:e.target.dataset.type})
            typeMethod[e.target.dataset.type]();
            this.emitEvent();
          },
        
        
        
          doSearchAchievement(e) {
            const typeMethod= {
              //全部
              '2': () => {
                this.setData({
                  achievementName: '全部'
                })
              },
              //合格
              '1': () => {
                this.setData({
                  achievementName: '合格'
                })
              },
              //未合格
              '0': () => {
                this.setData({
                  achievementName: '未合格'
                })
              }
             
            }
        
            this.setData({achievementType:e.target.dataset.type})
            typeMethod[e.target.dataset.type]();
            this.emitEvent();
          }
    },
    lifetimes:{
      created: function(){

      },
      attached: function(){
  
      },
      ready: function(){
      },
      moved: function(){
  
      },
      detached: function(){
  
      }
    }
    
});